import { defineStore } from 'pinia'

// 不用写mutation了, 
// 每个pinia的模块都是一个独立的store
export const useCounterStore = defineStore({
  id: 'counter', // 标识名称, 每个模块都要不同
  state: () => ({
    count: 0
  }),
  getters: {
    doubleCount: (state) => state.count * 2
  },
  actions: {
    increment() {
      this.count++
    },

    decrement() {
      this.count--
    },

    incrementAsync () {
      setTimeout(() => {
        this.count++
      }, 1000);
    }
  }
})